home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / info / cc-mode.info-1 < prev    next >
Encoding:
GNU Info File  |  1995-09-01  |  46.3 KB  |  1,199 lines

  1. This is Info file ../info/cc-mode.info, produced by Makeinfo-1.63 from
  2. the input file cc-mode.texi.
  3.  
  4.    Copyright (C) 1995 Free Software Foundation, Inc.
  5.  
  6. 
  7. File: cc-mode.info,  Node: Top,  Next: Introduction,  Prev: (dir),  Up: (dir)
  8.  
  9. * Menu:
  10.  
  11. * Introduction::
  12. * Getting Connected::
  13. * New Indentation Engine::
  14. * Minor Modes::
  15. * Indentation Commands::
  16. * Customizing Indentation::
  17. * Syntactic Symbols::
  18. * Performance Issues::
  19. * Frequently Asked Questions::
  20. * Getting the latest cc-mode release::
  21. * Sample .emacs File::
  22. * Requirements::
  23. * Limitations and Known Bugs::
  24. * Mailing Lists and Submitting Bug Reports::
  25. * Concept Index::
  26. * Command Index::               Command Index
  27. * Key Index::                   Key Index
  28. * Variable Index::              Variable Index
  29.  
  30. 
  31. File: cc-mode.info,  Node: Introduction,  Next: Getting Connected,  Prev: Top,  Up: Top
  32.  
  33. Introduction
  34. ************
  35.  
  36.    Welcome to `cc-mode', version 4.  This is a GNU Emacs mode for
  37. editing files containing C, C++, and Objective-C code.  This
  38. incarnation of the mode is descendant from `c-mode.el' (also called
  39. "Boring Old C Mode" or BOCM `:-)', and `c++-mode.el' version 2, which I
  40. have been maintaining since 1992.  `cc-mode' represents a significant
  41. milestone in the mode's life.  It has been fully merged back with Emacs
  42. 19's `c-mode.el'. Also a new, more intuitive and flexible mechanism for
  43. controlling indentation has been developed.
  44.  
  45.    `cc-mode' version 4 supports the editing of K&R and ANSI C, "ARM"
  46. (1) C++, and Objective-C files.  In this way, you can easily set up
  47. consistent coding styles for use in editing all C, C++, and Objective-C
  48. programs.
  49.  
  50.    This manual will describe the following:
  51.  
  52.    * How to get started using `cc-mode'.
  53.  
  54.    * How the new indentation engine works.
  55.  
  56.    * How to customize the new indentation engine.
  57.  
  58.    Note that the name of this file is `cc-mode.el', and I'll often
  59. refer to the package as `cc-mode', but there really is no top level
  60. `cc-mode' entry point.  I call it `cc-mode' simply to differentiate it
  61. from `c-mode.el'.  All of the variables, commands, and functions in
  62. `cc-mode' are prefixed with `c-<thing>', and `c-mode', `c++-mode', and
  63. `objc-mode' entry points are provided.  This file is intended to be a
  64. replacement for `c-mode.el' and `c++-mode.el'.
  65.  
  66.    The major version number was incremented to 4 with the addition of
  67. `objc-mode'. To find the minor revision number of this release, use
  68. `M-x c-version RET'.  This release will be the last for major release
  69. version 4 and the last release for which Emacs 18 will be supported.
  70. Work has already begun on `cc-mode' version 5.
  71.  
  72.    XEmacs 19.11 (formerly Lucid Emacs) is distributed with `cc-mode'
  73. 4.85 as its default C and C++ editing modes; it has completely replaced
  74. `c-mode.el' and `c++-mode.el'.  If you have XEmacs 19.11 or 19.12 you
  75. should upgrade your `cc-mode.el' to version 4.241 (see *Note Getting
  76. the latest cc-mode release::).  XEmacs 19.13 will be distributed with
  77. version 4.241.
  78.  
  79.    Both XEmacs and this distribution also contain a new file called
  80. `cc-compat.el' which should ease your transition from BOCM to
  81. `cc-mode'.  It currently comes unguaranteed and unsupported, but this
  82. may change for future versions.
  83.  
  84.    A special word of thanks goes to Krishna Padmasola for his work in
  85. converting the original `README' file to texinfo format.  `cc-mode'
  86. users have been clamoring for a manual for a long time, and thanks to
  87. Krishna, it is now available <clap> <clap> <clap>!  `:-)'
  88.  
  89.    ---------- Footnotes ----------
  90.  
  91.    (1)  i.e. "The Annotated C++ Reference Manual", by Ellis and
  92. Stroustrup.
  93.  
  94. 
  95. File: cc-mode.info,  Node: Getting Connected,  Next: New Indentation Engine,  Prev: Introduction,  Up: Top
  96.  
  97. Getting Connected
  98. *****************
  99.  
  100.    `cc-mode.el' works well with the 2 main branches of Emacs 19: XEmacs
  101. and the Emacs 19 maintained by the FSF.  FSF's Emacs 19 users will want
  102. to use Emacs version 19.21 or better, XEmacs users will want 19.6 or
  103. better.  Earlier versions of these Emacsen have deficiencies and/or
  104. bugs which will adversely affect the performance and usability of
  105. `cc-mode'.
  106.  
  107.    Similarly if you use the `cc-mode-18.el' compatibility file,
  108. `cc-mode.el' will work with Emacs 18, but only moderately well.  A word
  109. of warning though, *Emacs 18 lacks some fundamental functionality and
  110. that ultimately means using Emacs 18 is a losing battle*.  Hence
  111. `cc-mode' under Emacs 18 is no longer supported and it is highly
  112. recommended that you upgrade to Emacs 19.  If you use `cc-mode' under
  113. Emacs 18, you're on your own.  With `cc-mode' version 5, Emacs 18
  114. support will be dropped altogether.
  115.  
  116.    Note that XEmacs 19.13 already comes with the latest `cc-mode'
  117. version 4 preconfigured for your use.  You should be able to safely skip
  118. the rest of the setup information in this chapter.  XEmacs 19.11 and
  119. 19.12 ships older versions of `cc-mode', so those users will want to
  120. continue reading to learn how to upgrade to the latest `cc-mode'
  121. version 4 (see *Note Getting the latest cc-mode release::).
  122.  
  123.    The first thing you will want to do is put `cc-mode.el' somewhere on
  124. your `load-path' so Emacs can find it.  Do a `C-h v load-path RET' to
  125. see all the directories Emacs looks at when loading a file.  If none of
  126. these directories are appropriate, create a new directory and add it to
  127. your `load-path':
  128.  
  129. *[in the shell]*
  130.  
  131.      % cd
  132.      % mkdir mylisp
  133.      % mv cc-mode.el mylisp
  134.      % cd mylisp
  135.  
  136. *[in your .emacs file add]*
  137.  
  138.      (setq load-path (cons "~/mylisp" load-path))
  139.  
  140.    Next you want to "byte compile" `cc-mode.el'.  The mode uses a lot
  141. of macros so if you don't byte compile it, things will be unbearably
  142. slow.  *You can ignore all byte-compiler warnings!*  They are the
  143. result of the supporting different versions of Emacs, and none of the
  144. warnings have any effect on operation. Let me say this again: *You
  145. really can ignore all byte-compiler warnings!*
  146.  
  147.    Here's what to do to byte-compile the file [in emacs]:
  148.  
  149.      M-x byte-compile-file RET ~/mylisp/cc-mode.el RET
  150.  
  151.    If you are running XEmacs 19.11 or 19.12, you can simply add the
  152. following to your `.emacs' file in order to upgrade to the latest
  153. version of `cc-mode':
  154.  
  155.      (load "cc-mode")
  156.  
  157.    Users of FSF's Emacs 19, Emacs 18, or of the older Lucid Emacs will
  158. probably be running an Emacs that has BOCM `c-mode.el' and possible
  159. `c++-mode.el' pre-dumped.  If your Emacs is dumped with either of these
  160. files you first need to make Emacs "forget" about those older modes.
  161.  
  162.    If you can do a `C-h v c-mode-map RET' without getting an error, you
  163. need to add these lines at the top of your `.emacs' file:
  164.  
  165.      (fmakunbound 'c-mode)
  166.      (makunbound  'c-mode-map)
  167.      (fmakunbound 'c++-mode)
  168.      (makunbound  'c++-mode-map)
  169.      (makunbound  'c-style-alist)
  170.  
  171.    After those lines you will want to add the following autoloads to
  172. your `.emacs' file so that `cc-mode' gets loaded at the right time:
  173.  
  174.      (autoload 'c++-mode  "cc-mode" "C++ Editing Mode" t)
  175.      (autoload 'c-mode    "cc-mode" "C Editing Mode" t)
  176.      (autoload 'objc-mode "cc-mode" "Objective-C Editing Mode" t)
  177.  
  178.    Alternatively, if you want to make sure `cc-mode' is loaded when
  179. Emacs starts up, you could use this line instead of the three autoloads
  180. above:
  181.  
  182.      (require 'cc-mode)
  183.  
  184.    Next, you will want to set up Emacs so that it edits C files in
  185. `c-mode', C++ files in `c++-mode', and Objective-C files in
  186. `objc-mode'. All users should add the following to their `.emacs' file.
  187. Note that this assumes you'll be editing `.h' and `.c' files as C,
  188. `.hh', `.cc', `.H', and `.C' files as C++, and `.m' files as
  189. Objective-C. YMMV:
  190.  
  191.      (setq auto-mode-alist
  192.        (append
  193.          '(("\\.C$"  . c++-mode)
  194.            ("\\.H$"  . c++-mode)
  195.            ("\\.cc$" . c++-mode)
  196.            ("\\.hh$" . c++-mode)
  197.            ("\\.c$"  . c-mode)
  198.            ("\\.h$"  . c-mode)
  199.            ("\\.m$"  . objc-mode)
  200.           ) auto-mode-alist))
  201.  
  202.    You may already have some or all of these settings on your
  203. `auto-mode-alist', but it won't hurt to put them on there again.
  204.  
  205.    That's all you need - I know, I know, it sounds like a lot `:-)',
  206. but after you've done all this, you should only need to quit and restart
  207. Emacs.  The next time you visit a C, C++, or Objective-C file you should
  208. be using `cc-mode'.  You can check this easily by hitting `M-x
  209. c-version RET' in the `c-mode', `c++-mode', or `objc-mode' buffer.  You
  210. should see this message in the echo area:
  211.  
  212.      Using `cc-mode' version 4.241.
  213.  
  214. * Menu:
  215.  
  216. * Syntactic Analysis::
  217. * Indentation Calculation::
  218.  
  219. 
  220. File: cc-mode.info,  Node: New Indentation Engine,  Next: Minor Modes,  Prev: Getting Connected,  Up: Top
  221.  
  222. New Indentation Engine
  223. **********************
  224.  
  225.    `cc-mode' has a new indentation engine, providing a simplified, yet
  226. flexible and general mechanism for customizing indentation. It breaks
  227. indentation calculation into two steps. First for the line of code being
  228. indented, `cc-mode' analyzes what kind of language construct it's
  229. looking at, then it applies user defined offsets to the current line
  230. based on this analysis.
  231.  
  232.    This section will briefly cover how indentation is calculated in
  233. `cc-mode'. It is important to understand the indentation model being
  234. used so that you will know how to customize `cc-mode' for your personal
  235. coding style.
  236.  
  237. * Menu:
  238.  
  239. * Syntactic Analysis::
  240. * Indentation Calculation::
  241.  
  242. 
  243. File: cc-mode.info,  Node: Syntactic Analysis,  Next: Indentation Calculation,  Up: New Indentation Engine
  244.  
  245. Syntactic Analysis
  246. ==================
  247.  
  248.    The first thing `cc-mode' does when indenting a line of code, is to
  249. analyze the line, determining the "syntactic component list" of the
  250. construct on that line.  A "syntactic component" consists of a pair of
  251. information (in lisp parlance, a *cons cell*), where the first part is
  252. a "syntactic symbol", and the second part is a "relative buffer
  253. position".  Syntactic symbols describe elements of C code (1), e.g.
  254. `statement', `substatement', `class-open', `class-close', etc.  *Note
  255. Syntactic Symbols::, for a complete list of currently recognized
  256. syntactic symbols and their semantics.  The variable `c-offsets-alist'
  257. also contains the list of currently supported syntactic symbols.
  258.  
  259.    Conceptually, a line of C code is always indented relative to the
  260. indentation of some line higher up in the buffer.  This is represented
  261. by the relative buffer position in the syntactic component.
  262.  
  263.    It might help to see an example. Suppose we had the following code as
  264. the only thing in a `c++-mode' buffer (2):
  265.  
  266.        1: void swap( int& a, int& b )
  267.        2: {
  268.        3:     int tmp = a;
  269.        4:     a = b;
  270.        5:     b = tmp;
  271.        6: }
  272.  
  273.    We can use the command `C-c C-s' (`c-show-syntactic-information') to
  274. simply report what the syntactic analysis is for the current line.
  275. Running this command on line 4 this example, we'd see in the echo area:
  276.  
  277.      ((statement . 35))
  278.  
  279.    This tells us that the line is a statement and it is indented
  280. relative to buffer position 35, which happens to be the `i' in `int' on
  281. line 3.  If you were to move point to line 3 and hit `C-c C-s', you
  282. would see:
  283.  
  284.      ((defun-block-intro . 29))
  285.  
  286.    This indicates that the `int' line is the first statement in a top
  287. level function block, and is indented relative to buffer position 29,
  288. which is the brace just after the function header.
  289.  
  290.    Here's another example:
  291.  
  292.        1: int add( int val, int incr, int doit )
  293.        2: {
  294.        3:     if( doit )
  295.        4:         {
  296.        5:             return( val + incr );
  297.        6:         }
  298.        7:     return( val );
  299.        8: }
  300.  
  301. Hitting `C-c C-s' on line 4 gives us:
  302.  
  303.      ((substatement-open . 46))
  304.  
  305. which tells us that this is a brace that *opens* a substatement block.
  306. (3)
  307.  
  308.    Syntactic component lists can contain more than one component, and
  309. individual syntactic components need not have relative buffer positions.
  310. The most common example of this is a line that contains a "comment only
  311. line".
  312.  
  313.        1: void draw_list( List<Drawables>& drawables )
  314.        2: {
  315.        3:         // call the virtual draw() method on each element in list
  316.        4:     for( int i=0; i < drawables.count(), ++i )
  317.        5:     {
  318.        6:         drawables[i].draw();
  319.        7:     }
  320.        8: }
  321.  
  322. Hitting `C-c C-s' on line 3 of example 3 gives us:
  323.  
  324.      ((comment-intro) (defun-block-intro . 46))
  325.  
  326. so you can see that the syntactic component list contains two syntactic
  327. components.  Also notice that the first component, `(comment-intro)'
  328. has no relative buffer position.
  329.  
  330.    ---------- Footnotes ----------
  331.  
  332.    (1)  or C++, or Objective-C code.  In general, for the rest of this
  333. manual I'll use the term "C code" to refer to all the C-like dialects,
  334. unless otherwise noted.
  335.  
  336.    (2)  The line numbers in this and future examples don't actually
  337. appear in the buffer, of course!
  338.  
  339.    (3)  A "substatement" indicates the line after an `if', `else',
  340. `while', `do', `switch', or `for' statement, and a "substatement block"
  341. is a brace block following one of those constructs.
  342.  
  343. 
  344. File: cc-mode.info,  Node: Indentation Calculation,  Prev: Syntactic Analysis,  Up: New Indentation Engine
  345.  
  346. Indentation Calculation
  347. =======================
  348.  
  349.    Indentation for the current line is calculated using the syntactic
  350. component list derived in step 1 above (see *Note Syntactic Analysis::).
  351. Each component contributes to the final total indentation of the line in
  352. two ways.
  353.  
  354.    First, the syntactic symbols are looked up in the `c-offsets-alist'
  355. variable, which is an association list of syntactic symbols and the
  356. offsets to apply for those symbols.  These offsets are added to the
  357. running total.
  358.  
  359.    Second, if the component has a relative buffer position, `cc-mode'
  360. adds the column number of that position to the running total.  By adding
  361. up the offsets and columns for every syntactic component on the list,
  362. the final total indentation for the current line is computed.
  363.  
  364.    Let's use our two code examples above to see how this works.  Here is
  365. our first example again:
  366.  
  367.          1: void swap( int& a, int& b )
  368.          2: {
  369.          3:     int tmp = a;
  370.          4:     a = b;
  371.          5:     b = tmp;
  372.          6: }
  373.  
  374.    Let's say point is on line 3 and we hit the TAB key to re-indent the
  375. line.  Remember that the syntactic component list for that line is:
  376.  
  377.      ((defun-block-intro . 29))
  378.  
  379. `cc-mode' looks up `defun-block-intro' in the `c-offsets-alist'
  380. variable.  Let's say it finds the value `4'; it adds this to the
  381. running total (initialized to zero), yielding a running total
  382. indentation of 4 spaces.
  383.  
  384.    Next `cc-mode' goes to buffer position 29 and asks for the current
  385. column.  Since the brace at buffer position 29 is in column zero, it
  386. adds `0' to the running total.  Since there is only one syntactic
  387. component on the list for this line, indentation calculation is
  388. complete, and the total indentation for the line is 4 spaces.
  389.  
  390.    Here's another example:
  391.  
  392.          1: int add( int val, int incr, int doit )
  393.          2: {
  394.          3:     if( doit )
  395.          4:         {
  396.          5:             return( val + incr );
  397.          6:         }
  398.          7:     return( val );
  399.          8: }
  400.  
  401.    If we were to hit `TAB' on line 4 in the above example, the same
  402. basic process is performed, despite the differences in the syntactic
  403. component list.  Remember that the list for this line is:
  404.  
  405.      ((substatement-open . 46))
  406.  
  407.    Here, `cc-mode' first looks up the `substatement-open' symbol in
  408. `c-offsets-alist'. Let's say it finds the value `4'.  This yields a
  409. running total of 4.  `cc-mode' then goes to buffer position 46, which
  410. is the `i' in `if' on line 3.  This character is in the fourth column
  411. on that line so adding this to the running total yields an indentation
  412. for the line of 8 spaces.
  413.  
  414.    Simple, huh?
  415.  
  416.    Actually, the mode usually just does The Right Thing without you
  417. having to think about it in this much detail.  But when customizing
  418. indentation, it's helpful to understand the general indentation model
  419. being used.
  420.  
  421.    To help you configure `cc-mode', you can set the variable
  422. `c-echo-syntactic-information-p' to non-`nil' so that the syntactic
  423. component list and calculated offset will always be echoed in the
  424. minibuffer when you hit `TAB'.
  425.  
  426. 
  427. File: cc-mode.info,  Node: Minor Modes,  Next: Indentation Commands,  Prev: New Indentation Engine,  Up: Top
  428.  
  429. Minor Modes
  430. ***********
  431.  
  432.    `cc-mode' contains two minor-mode-like features that you should find
  433. useful while you enter new C code.  The first is called "auto-newline"
  434. mode, and the second is called "hungry-delete" mode.  These minor modes
  435. can be toggled on and off independently, and `cc-mode' can be
  436. configured so that it comes up with any combination of these minor
  437. modes.  By default, both of these minor modes are turned off.
  438.  
  439.    The state of the minor modes is always reflected in the minor mode
  440. list on the modeline of the `cc-mode' buffer.  When auto-newline mode is
  441. enabled, you will see `C/a' on the mode line (1).  When hungry delete
  442. mode is enabled you would see `C/h' and when mode modes are enabled,
  443. you'd see `C/ah'.
  444.  
  445.    `cc-mode' provides keybindings which allow you to toggle the minor
  446. modes while editing code on the fly.  To toggle just the auto-newline
  447. state, hit `C-c C-a' (`c-toggle-auto-state').  When you do this, you
  448. should see the `a' indicator either appear or disappear on the
  449. modeline.  Similarly, to toggle just the hungry-delete state, use `C-c
  450. C-d' (`c-toggle-hungry-state'), and to toggle both states together, use
  451. `C-c C-t' (`c-toggle-auto-hungry-state').
  452.  
  453.    To set up the auto-newline and hungry-delete states to your preferred
  454. values, you would need to add some lisp to your `.emacs' file that
  455. called one of the `c-toggle-*-state' functions directly.  When called
  456. programmatically, each function takes a numeric value, where a positive
  457. number enables the minor mode, a negative number disables the mode, and
  458. zero toggles the current state of the mode.
  459.  
  460.    So for example, if you wanted to enable both auto-newline and
  461. hungry-delete for all your C file editing, you could add the following
  462. to your `.emacs' file:
  463.  
  464.      (add-hook 'c-mode-common-hook '(lambda () (c-toggle-auto-hungry-state 1)))
  465.  
  466. * Menu:
  467.  
  468. * Auto-newline insertion::
  469. * Hungry-deletion of whitespace::
  470.  
  471.    ---------- Footnotes ----------
  472.  
  473.    (1)  Remember that the `C' would be replaced with `C++' or `ObjC' if
  474. you were editing C++ or Objective-C code.
  475.  
  476. 
  477. File: cc-mode.info,  Node: Auto-newline insertion,  Next: Hungry-deletion of whitespace,  Up: Minor Modes
  478.  
  479. Auto-newline insertion
  480. ======================
  481.  
  482.    Auto-newline minor mode works by enabling certain "electric
  483. commands".  Electric commands are typically bound to special characters
  484. such as the left and right braces, colons, semi-colons, etc., which when
  485. typed, perform some magic formatting in addition to inserting the typed
  486. character.  As a general rule, electric commands are only electric when
  487. the following conditions apply:
  488.  
  489.    * Auto-newline minor mode is enabled, as evidenced by a `C/a' or
  490.      `C/ah' indicator on the modeline.
  491.  
  492.    * The character was not typed inside of a literal (1).
  493.  
  494.    * No numeric argument was supplied to the command (i.e. it was typed
  495.      as normal, with no `C-u' prefix).
  496.  
  497.    Certain other conditions may apply on a language specific basis.  For
  498. example, the second slash (`/') of a C++ style line comment is electric
  499. in `c++-mode' and `objc-mode', but not in `c-mode'.
  500.  
  501. * Menu:
  502.  
  503. * Hanging Braces::
  504. * Hanging Colons::
  505. * Hanging Semi-colons and commas::
  506. * Other electric commands::
  507. * Clean-ups::
  508.  
  509.    ---------- Footnotes ----------
  510.  
  511.    (1)  A "literal" is defined in `cc-mode' as any comment, string, or
  512. cpp macro definition.  These constructs are also known as "syntactic
  513. whitespace" since they are usually ignored when scanning C code.
  514.  
  515. 
  516. File: cc-mode.info,  Node: Hanging Braces,  Next: Hanging Colons,  Up: Auto-newline insertion
  517.  
  518. Hanging Braces
  519. --------------
  520.  
  521.    When you type either an open or close brace (i.e. `{' or `}'), the
  522. electric command `c-electric-brace' gets run.  This command has two
  523. electric formatting behaviors.  First, it will perform some
  524. re-indentation of the line the brace was typed on, and second, it will
  525. add various newlines before and/or after the typed brace.
  526. Re-indentation occurs automatically whenever the electric behavior is
  527. enabled.  If the brace ends up on a line other than the one it was typed
  528. on, then that line is on is also indented according to
  529. `c-offsets-alist'.
  530.  
  531.    The insertion of newlines is controlled by the
  532. `c-hanging-braces-alist' variable.  This variable contains a mapping
  533. between syntactic symbols related to braces, and a list of places to
  534. insert a newline.  The syntactic symbols that are useful for this list
  535. are: `class-open', `class-close', `defun-open', `defun-close',
  536. `inline-open', `inline-close', `brace-list-open', `brace-list-close',
  537. `brace-list-intro', `brace-list-entry', `block-open', `block-close',
  538. `substatement-open', and `statement-case-open'.  *Note Syntactic
  539. Symbols:: for a more detailed description of these syntactic symbols.
  540.  
  541.    The value associated with each syntactic symbol in this association
  542. list is called an ACTION which can be either a function or a list.
  543. *Note Custom Brace and Colon Hanging:: for a more detailed discussion of
  544. using a function as a brace hanging ACTION.
  545.  
  546.    When ACTION is a list, it can contain any combination of the symbols
  547. `before' or `after', directing `cc-mode' where to put newlines in
  548. relationship to the brace being inserted.  Thus, if the list contains
  549. only the symbol `after', then the brace is said to "hang" on the right
  550. side of the line, as in:
  551.  
  552.      // here, open braces always `hang'
  553.      void spam( int i ) {
  554.          if( i == 7 ) {
  555.              dosomething(i);
  556.          }
  557.      }
  558.  
  559.    When the list contains both `after' and `before', the braces will
  560. appear on a line by themselves, as shown by the close braces in the
  561. above example.  The list can also be empty, in which case no newlines
  562. are added either before or after the brace.
  563.  
  564.    For example, the default value of `c-hanging-braces-alist' is:
  565.  
  566.      (defvar c-hanging-braces-alist '((brace-list-open)
  567.                                       (substatement-open after)
  568.                                       (block-close . c-snug-do-while)))
  569.  
  570. which says that `brace-list-open' braces should both hang on the right
  571. side, and allow subsequent text to follow on the same line as the
  572. brace.  Also, `substatement-open' braces should hang on the right side,
  573. but subsequent text should follow on the next line.  Here, in the
  574. `block-close' entry, you also see an example of using a function as an
  575. ACTION.
  576.  
  577. 
  578. File: cc-mode.info,  Node: Hanging Colons,  Next: Hanging Semi-colons and commas,  Prev: Hanging Braces,  Up: Auto-newline insertion
  579.  
  580. Hanging Colons
  581. --------------
  582.  
  583.    Using a mechanism similar to brace hanging (see *Note Hanging
  584. Braces::), colons can also be made to hang using the variable
  585. `c-hanging-colons-alist'.  The syntactic symbols appropriate for this
  586. assocation list are: `case-label', `label', `access-label',
  587. `member-init-intro', and `inher-intro'.  *Note Hanging Braces:: and
  588. *Note Custom Brace and Colon Hanging:: for details.  Note however, that
  589. `c-hanging-colons-alist' does not implement functions as ACTIONs.
  590.  
  591.    In C++, double-colons are used as a scope operator but because these
  592. colons always appear right next to each other, newlines before and after
  593. them are controlled by a different mechanism, called "clean-ups" in
  594. `cc-mode'.  *Note Clean-ups:: for details.
  595.  
  596. 
  597. File: cc-mode.info,  Node: Hanging Semi-colons and commas,  Next: Other electric commands,  Prev: Hanging Colons,  Up: Auto-newline insertion
  598.  
  599. Hanging Semi-colons and commas
  600. ------------------------------
  601.  
  602.    Semicolons and commas are also electric in `cc-mode', but since
  603. these characters do not correspond directly to syntactic symbols, a
  604. different mechanism is used to determine whether newlines should be
  605. automatically inserted after these characters.  *Note Customizing
  606. Semi-colons and Commas:: for details.
  607.  
  608. 
  609. File: cc-mode.info,  Node: Other electric commands,  Next: Clean-ups,  Prev: Hanging Semi-colons and commas,  Up: Auto-newline insertion
  610.  
  611. Other electric commands
  612. -----------------------
  613.  
  614.    A few other keys also provide electric behavior.  For example the
  615. `#' key (`c-electric-pound') is electric when it is typed as the first
  616. non-whitespace character on a line.  In this case, the variable
  617. `c-electric-pound-behavior' is consulted for the electric behavior.
  618. This variable takes a list value, although the only element currently
  619. defined is `alignleft', which tells this command to force the `#'
  620. character into column zero.  This is useful for entering cpp macro
  621. definitions.
  622.  
  623.    Stars and slashes (i.e. `*' and `/') are also electric under certain
  624. circumstances.  If a star is inserted as the second character of a C
  625. style block comment on a "comment-only" line, then the comment
  626. delimiter is indented as defined by `c-offsets-alist'.  A comment-only
  627. line is defined as a line which contains only a comment, as in:
  628.  
  629.      void spam( int i )
  630.      {
  631.              // this is a comment-only line...
  632.          if( i == 7 )                             // but this is not
  633.          {
  634.              dosomething(i);
  635.          }
  636.      }
  637.  
  638.    Likewise, if a slash is inserted as the second slash in a C++ style
  639. line comment (also only on a comment-only line), then the line is
  640. indented as defined by `c-offsets-alist'.
  641.  
  642. 
  643. File: cc-mode.info,  Node: Clean-ups,  Prev: Other electric commands,  Up: Auto-newline insertion
  644.  
  645. Clean-ups
  646. ---------
  647.  
  648.    "Clean-ups" are a mechanism complementary to colon and brace
  649. hanging.  On the surface, it would see that clean-ups overlap the
  650. functionality provided by the `c-hanging-*-alist' variables, and
  651. similarly, clean-ups are only enabled when auto-newline minor mode is
  652. enabled.  Clean-ups are used however to adjust code "after-the-fact",
  653. i.e. to eliminate some whitespace that isn't inserted by electric
  654. commands, or whitespace that contains intervening constructs.
  655.  
  656.    You can configure `cc-mode''s clean-ups by setting the variable
  657. `c-cleanup-list', which is a list of clean-up symbols.  By default,
  658. `cc-mode' cleans up only the `scope-operator' construct, which is
  659. necessary for proper C++ support.  Note that clean-ups are only
  660. performed when the construct does not occur within a literal (see *Note
  661. Auto-newline insertion::), and when there is nothing but whitespace
  662. appearing between the individual components of the construct.
  663.  
  664.    There are currently only five specific constructs that `cc-mode' can
  665. clean up, as indicated by these symbols:
  666.  
  667.    * `brace-else-brace' - cleans up `} else {' constructs by placing
  668.      the entire construct on a single line.  Clean-up occurs when the
  669.      open brace after the `else' is typed.  So for example, this:
  670.  
  671.           void spam(int i)
  672.           {
  673.               if( i==7 )
  674.               {
  675.                   dosomething();
  676.               }
  677.               else
  678.               {
  679.  
  680.      appears like this after the open brace is typed:
  681.  
  682.           void spam(int i)
  683.           {
  684.               if( i==7 ) {
  685.                   dosomething();
  686.               } else {
  687.  
  688.    * `empty-defun-braces' - cleans up braces following a top-level
  689.      function or class definition that contains no body.  Clean up
  690.      occurs when the closing brace is typed.  Thus the following:
  691.  
  692.           class Spam
  693.           {
  694.           }
  695.  
  696.      is transformed into this when the close brace is typed:
  697.  
  698.           class Spam
  699.           {}
  700.  
  701.    * `defun-close-semi' - cleans up the terminating semi-colon on
  702.      top-level function or class definitions when they follow a close
  703.      brace. Clean up occurs when the semi-colon is typed.  So for
  704.      example, the following:
  705.  
  706.           class Spam
  707.           {
  708.           }
  709.           ;
  710.  
  711.      is transformed into this when the semi-colon is typed:
  712.  
  713.  
  714.           class Spam
  715.           {
  716.           };
  717.  
  718.    * `list-close-comma' - cleans up commas following braces in array
  719.      and aggregate initializers.  Clean up occurs when the comma is
  720.      typed.
  721.  
  722.    * `scope-operator' - cleans up double colons which may designate a
  723.      C++ scope operator split across multiple lines(1).  Clean up
  724.      occurs when the second colon is typed.  You will always want
  725.      `scope-operator' in the `c-cleanup-list' when you are editing C++
  726.      code.
  727.  
  728.    ---------- Footnotes ----------
  729.  
  730.    (1)  Certain C++ constructs introduce ambiguous situations, so
  731. `scope-operator' clean-ups may not always be correct.  This usually
  732. only occurs when scoped identifiers appear in switch label tags.
  733.  
  734. 
  735. File: cc-mode.info,  Node: Hungry-deletion of whitespace,  Prev: Auto-newline insertion,  Up: Minor Modes
  736.  
  737. Hungry-deletion of whitespace
  738. =============================
  739.  
  740.    Hungry deletion of whitespace, or as it more commonly called,
  741. "hungry-delete mode", is a simple feature that some people find
  742. extremely useful.  In fact, you might find yourself wanting
  743. hungry-delete in *all* your editing modes!
  744.  
  745.    In a nutshell, when hungry-delete mode is enabled, hitting the `DEL'
  746. character will consume all preceding whitespace, including newlines and
  747. tabs.  This can really cut down on the number of `DEL''s you have to
  748. type if, for example you made a mistake on the preceding line.
  749.  
  750.    By default, `cc-mode' actually runs the command `c-electric-delete'
  751. when you hit `DEL'.  When this command is used to delete a single
  752. character (i.e. when it is called interactively with no numeric
  753. argument), it really runs the function contained in the variable
  754. `c-delete-function'.  This function is called with a single argument,
  755. which is the number of characters to delete.  `c-delete-function' is
  756. also called when the `DEL' key is typed inside a literal (see *Note
  757. Auto-newline insertion::.  Inside a literal, `c-electric-delete' is not
  758. electric, which is typical of all the so-called electric commands.
  759.  
  760. 
  761. File: cc-mode.info,  Node: Indentation Commands,  Next: Customizing Indentation,  Prev: Minor Modes,  Up: Top
  762.  
  763. Indentation Commands
  764. ********************
  765.  
  766.    Various commands are provided which allow you to conveniently
  767. re-indent C constructs, and these are outlined below.  There are
  768. several things to note about these indentation commands.  First, when
  769. you change your programming style, either though `c-set-style' or some
  770. other means, your file does *not* automatically get re-indented.  When
  771. you change style parameters, you will typically need to reformat the
  772. line, expression, or buffer to see the effects of your changes.
  773.  
  774.    Second, changing some variables have no effect on existing code, even
  775. when you do re-indent.  For example, the `c-hanging-*' variables and
  776. `c-cleanup-list' only affect newly entered code.  So for example,
  777. changing `c-hanging-braces-alist' and re-indenting the buffer will not
  778. adjust placement of braces already in the file.
  779.  
  780.    Third, re-indenting large portions of code is currently rather
  781. inefficient.  Improvements have been made since previous releases of
  782. `cc-mode', and much more radical improvements will be made for the next
  783. release, but for now you need to be aware of this (1).  Some provision
  784. has been made to at least inform you as to the progress of your large
  785. re-indentation command.  The variable `c-progress-interval' controls
  786. how often a progress message is displayed.  Set this variable to `nil'
  787. to inhibit progress messages.  Note that this feature only works with
  788. Emacs 19.
  789.  
  790.    Also, except as noted below, re-indentation is always driven by the
  791. same mechanisms that control on-the-fly indentation of code.  *Note New
  792. Indentation Engine:: for details.
  793.  
  794.    To indent a single line of code, use `TAB' (`c-indent-command').
  795. The behavior of this command is controlled by the variable
  796. `c-tab-always-indent'.  When this variable is `t', `TAB' always just
  797. indents the current line.  When `nil', the line is indented only if
  798. point is at the left margin, or on or before the first non-whitespace
  799. character on the line, otherwise a real tab character is inserted.  If
  800. this variable's value is something other that `t' or `nil' (e.g.
  801. `'other'), then a real tab character is inserted only when point is
  802. inside a literal (see *Note Auto-newline insertion::), otherwise the
  803. line is indented.
  804.  
  805.    To indent an entire balanced brace or parenthesis expression, use
  806. `M-C-q' (`c-indent-exp').  Note that point should be on the opening
  807. brace or parenthesis of the expression you want to indent.
  808.  
  809.    Another very convenient keystroke is `C-c C-q' (`c-indent-defun')
  810. when re-indents the entire top-level function or class definition that
  811. encompases point.  It leaves point at the same position within the
  812. buffer.
  813.  
  814.    To indent any arbitrary region of code, use `M-C-\'
  815. (`indent-region').   This is a standard Emacs command, specially
  816. tailored for C code in a `cc-mode' buffer.  Note that of course, point
  817. and mark must delineate the region you want to indent.
  818.  
  819.    While not strictly an indentation function, `M-C-h'
  820. (`c-mark-function') is useful for marking the current top-level
  821. function or class definition as the current region.
  822.  
  823.    ---------- Footnotes ----------
  824.  
  825.    (1)  In particular, I have had people complain about the speed that
  826. `cc-mode' re-indents `lex(1)' output.  Lex, yacc, and other code
  827. generators usually output some pretty perverse code.  *Don't* try to
  828. indent this stuff with `cc-mode'!
  829.  
  830. 
  831. File: cc-mode.info,  Node: Customizing Indentation,  Next: Syntactic Symbols,  Prev: Indentation Commands,  Up: Top
  832.  
  833. Customizing Indentation
  834. ***********************
  835.  
  836.    The `c-offsets-alist' variable is where you customize all your
  837. indentations.  You simply need to decide what additional offset you want
  838. to add for every syntactic symbol.  You can use the command `C-c C-o'
  839. (`c-set-offset') as the way to set offsets, both interactively and from
  840. your mode hook.  Also, you can set up *styles* of indentation just like
  841. in BOCM.  Most likely, you'll find one of the pre-defined styles will
  842. suit your needs, but if not, this section will describe how to set up
  843. basic editing configurations.  *Note Styles:: for an explanation of how
  844. to set up named styles.
  845.  
  846.    As mentioned previously, the variable `c-offsets-alist' is an
  847. association list between syntactic symbols and the offsets to be applied
  848. for those symbols.  In fact, these offset values can be an integer, a
  849. function or variable name, or one of the following symbols: `+', `-',
  850. `++', `--', `*', or `/'.  These symbols describe offset in multiples of
  851. the value of the variable `c-basic-offset'.  By defining a style's
  852. indentation in terms of this fundamental variable, you can change the
  853. amount of whitespace given to an indentation level while leaving the
  854. same relationship between levels.  Here are multiples of
  855. `c-basic-offset' that the special symbols correspond to:
  856.  
  857.    * `+ ' =  `c-basic-offset' times 1
  858.  
  859.    * `- ' =  `c-basic-offset' times -1
  860.  
  861.    * `++' =  `c-basic-offset' times 2
  862.  
  863.    * `--' =  `c-basic-offset' times -2
  864.  
  865.    * `* ' =  `c-basic-offset' times 0.5
  866.  
  867.    * `/ ' =  `c-basic-offset' times -0.5
  868.  
  869. So, for example, because most of the default offsets are defined in
  870. terms of `+', `-', and `0', if you like the general indentation style,
  871. but you use 4 spaces instead of 2 spaces per level, you can probably
  872. achieve your style just by changing `c-basic-offset' like so (in your
  873. `.emacs' file)(1):
  874.  
  875.      (setq-default c-basic-offset 4)
  876.  
  877. This would change
  878.  
  879.      int add( int val, int incr, int doit )
  880.      {
  881.          if( doit )
  882.              {
  883.                  return( val + incr );
  884.              }
  885.          return( val );
  886.      }
  887.  
  888. to
  889.  
  890.      int add( int val, int incr, int doit )
  891.      {
  892.        if( doit )
  893.          {
  894.            return( val + incr );
  895.          }
  896.        return( val );
  897.      }
  898.  
  899.    To change indentation styles more radically, you will want to change
  900. the value associated with the syntactic symbols in the
  901. `c-offsets-alist' variable.  First, I'll show you how to do that
  902. interactively, then I'll describe how to make changes to your `.emacs'
  903. file so that your changes are more permanent.
  904.  
  905. * Menu:
  906.  
  907. * Interactive Customization::
  908. * Permanent Customization::
  909. * Styles::
  910. * Advanced Customizations::
  911.  
  912.    ---------- Footnotes ----------
  913.  
  914.    (1)  The reason you need to use `setq-default' instead of `setq' is
  915. that `c-basic-offset' is a buffer local variable, as are most of the
  916. `cc-mode' configuration variables.  If you were to put this code in,
  917. e.g. your `c-mode-common-hook' function, you could use `setq'.
  918.  
  919. 
  920. File: cc-mode.info,  Node: Interactive Customization,  Next: Permanent Customization,  Up: Customizing Indentation
  921.  
  922. Interactive Customization
  923. =========================
  924.  
  925.    As an example of how to customize indentation, let's change the
  926. style of example 2 above from:
  927.  
  928.      1: int add( int val, int incr, int doit )
  929.      2: {
  930.      3:     if( doit )
  931.      4:         {
  932.      5:             return( val + incr );
  933.      6:         }
  934.      7:     return( val );
  935.      8: }
  936.  
  937. to:
  938.  
  939.      1: int add( int val, int incr, int doit )
  940.      2: {
  941.      3:     if( doit )
  942.      4:     {
  943.      5:         return( val + incr );
  944.      6:     }
  945.      7:     return( val );
  946.      8: }
  947.  
  948.    In other words, we want to change the indentation of braces that
  949. open a block following a condition so that the braces line up under the
  950. conditional, instead of being indented.  Notice that the construct we
  951. want to change starts on line 4.  To change the indentation of a line,
  952. we need to see which syntactic component affect the offset calculations
  953. for that line.  Hitting `C-c C-s' on line 4 yields:
  954.  
  955.      ((substatement-open . 46))
  956.  
  957. so we know that to change the offset of the open brace, we need to
  958. change the indentation for the `substatement-open' syntactic symbol.
  959. To do this interactively, just hit `C-c C-o' (`c-set-offset').  This
  960. prompts you for the syntactic symbol to change, providing a reasonable
  961. default.  In this case, the default is `substatement-open', which is
  962. just the syntactic symbol we want to change!
  963.  
  964.    After you hit return, `cc-mode' will then prompt you for the new
  965. offset value, with the old value as the default.  The default in this
  966. case is `+', so hit backspace to delete the `+', then hit `0' and
  967. `RET'.  This will associate the offset 0 with the syntactic symbol
  968. `substatement-open' in the `c-offsets-alist' variable.
  969.  
  970.    To check your changes quickly, just hit `C-c C-q' (`c-indent-defun')
  971. to reindent the entire function.  The example should now look like:
  972.  
  973.      1: int add( int val, int incr, int doit )
  974.      2: {
  975.      3:     if( doit )
  976.      4:     {
  977.      5:         return( val + incr );
  978.      6:     }
  979.      7:     return( val );
  980.      8: }
  981.  
  982.    Notice how just changing the open brace offset on line 4 is all we
  983. needed to do.  Since the other affected lines are indented relative to
  984. line 4, they are automatically indented the way you'd expect.  For more
  985. complicated examples, this may not always work.  The general approach to
  986. take is to always start adjusting offsets for lines higher up in the
  987. file, then re-indent and see if any following lines need further
  988. adjustments.
  989.  
  990. 
  991. File: cc-mode.info,  Node: Permanent Customization,  Next: Styles,  Prev: Interactive Customization,  Up: Customizing Indentation
  992.  
  993. Permanent Indentation
  994. =====================
  995.  
  996.    To make this change permanent, you need to add some lisp code to your
  997. `.emacs' file.  `cc-mode' provides four hooks that you can use to
  998. customize your language editing styles.  Three language specific hooks
  999. are provided, according to Emacs major mode conventions: `c-mode-hook',
  1000. `c++-mode-hook', and `objc-mode-hook'.  These get run as the last thing
  1001. when you enter `c-mode', `c++-mode', or `objc-mode' respectively.
  1002. `cc-mode' also provides a hook called `c-mode-common-hook' which is run
  1003. by all three modes *before* the language specific hook.  Thus, to make
  1004. changes consistently across all supported `cc-mode' modes, use
  1005. `c-mode-common-hook'.  Most of the examples in this section will assume
  1006. you are using the common hook.
  1007.  
  1008.    Here's a simplified example of what you can add to your `.emacs'
  1009. file to make the changes described in the previous section (*Note
  1010. Interactive Customization::) more permanent.  See the Emacs manuals for
  1011. more information on customizing Emacs via hooks.  *Note Sample .emacs
  1012. File:: for a more complete sample `.emacs' file.  (1)
  1013.  
  1014.      (defun my-c-mode-common-hook ()
  1015.        ;; my customizations for all of c-mode, c++-mode, and objc-mode
  1016.        (c-set-offset 'substatement-open 0)
  1017.        ;; other customizations can go here
  1018.        )
  1019.      (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
  1020.  
  1021.    For complex customizations, you will probably want to set up a
  1022. *style* that groups all your customizations under a single name.
  1023.  
  1024.    The offset value can also be a function, and this is how power users
  1025. gain enormous flexibility in customizing indentation. *Note Advanced
  1026. Customizations:: for details.
  1027.  
  1028.    ---------- Footnotes ----------
  1029.  
  1030.    (1)  The use of `add-hook' in this example only works for Emacs 19.
  1031. Workarounds are available if you are using Emacs 18.
  1032.  
  1033. 
  1034. File: cc-mode.info,  Node: Styles,  Next: Advanced Customizations,  Prev: Permanent Customization,  Up: Customizing Indentation
  1035.  
  1036. Styles
  1037. ======
  1038.  
  1039.    Most people only need to edit code formatted in just a few
  1040. well-defined and consistent styles.  For example, their organization
  1041. might impose a "blessed" style that all its programmers must conform
  1042. to.  Similarly, people who work on GNU software will have to use the
  1043. GNU coding style on C code.  Some shops are more lenient, allowing some
  1044. variety of coding styles, and as programmers come and go, there could
  1045. be a number of styles in use.  For this reason, `cc-mode' makes it
  1046. convenient for you to set up logical groupings of customizations called
  1047. "styles", associate a single name for any particular style, and pretty
  1048. easily start editing new or existing code using these styles.  This
  1049. chapter describes how to set up styles and how to edit your C code
  1050. using styles.
  1051.  
  1052. * Menu:
  1053.  
  1054. * Built-in Styles::
  1055. * Adding Styles::
  1056. * File Styles::
  1057.  
  1058. 
  1059. File: cc-mode.info,  Node: Built-in Styles,  Next: Adding Styles,  Up: Styles
  1060.  
  1061. Built-in Styles
  1062. ---------------
  1063.  
  1064.    If you're lucky, one of `cc-mode''s built-in styles might be just
  1065. what you're looking for.  Some of the most common C and C++ styles are
  1066. already built-in.  These include:
  1067.  
  1068.    * `GNU' - coding style blessed by the Free Software Foundation for C
  1069.      code in GNU programs.
  1070.  
  1071.    * `K&R' - The classic Kernighan and Ritchie style for C code.
  1072.  
  1073.    * `BSD' - *<TBD> Anybody know anything about the history of this
  1074.      style?*
  1075.  
  1076.    * `Stroustrup' - The classic Stroustrup style for C++ code.
  1077.  
  1078.    * `Whitesmith' - *<TBD> Anybody know anything about the history of
  1079.      this style?*
  1080.  
  1081.    * `Ellemtel' - Popular C++ coding standards as defined by
  1082.      "Programming in C++, Rules and Recommendations", Erik Nyquist and
  1083.      Mats Henricson, Ellemtel (1).
  1084.  
  1085.    * `CC-MODE' - Style that encapsulates the default values of the
  1086.      `cc-mode' variables.  See below for details.
  1087.  
  1088.    If you'd like to experiment with these built-in styles you can simply
  1089. type the following in a `cc-mode' buffer:
  1090.  
  1091.      `M-x c-set-style RET STYLE-NAME RET'
  1092.  
  1093. Note however that setting a style in this way does *not* automatically
  1094. re-indent your file.  For commands that you can use to view the effect
  1095. of your changes, see *Note Indentation Commands::.
  1096.  
  1097.    Once you find a built-in style you like, you can make the change
  1098. permanent by adding a call to your `.emacs' file.  Let's say for
  1099. example that you want to use the `Ellemtel' style in all your files.
  1100. You would add this:
  1101.  
  1102.      (defun my-c-mode-common-hook ()
  1103.        ;; use Ellemtel style for all C, C++, and Objective-C code
  1104.        (c-set-style "Ellemtel")
  1105.        ;; other customizations can go here
  1106.        )
  1107.      (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
  1108.  
  1109.    There is one other special style you can use, called `CC-MODE'.
  1110. This is a style that is calculated by `cc-mode' when it starts up.  The
  1111. `CC-MODE' style is also special because all other styles implicitly
  1112. inherit from it; in other words, whenever you set a style, `cc-mode'
  1113. first re-instates the `CC-MODE' style, then applies your new style
  1114. configurations.
  1115.  
  1116.    The `CC-MODE' style exists because once `cc-mode' initializes, it
  1117. institutes the `GNU' style for compatibility with BOCM's defaults.  Any
  1118. customizations you make in mode hooks will be based on the `GNU' style,
  1119. unless you first do a `c-set-style' to `CC-MODE' or some other built-in
  1120. style.
  1121.  
  1122.    ---------- Footnotes ----------
  1123.  
  1124.    (1)  This document is ftp'able from `euagate.eua.ericsson.se'
  1125.  
  1126. 
  1127. File: cc-mode.info,  Node: Adding Styles,  Next: File Styles,  Prev: Built-in Styles,  Up: Styles
  1128.  
  1129. Adding Styles
  1130. -------------
  1131.  
  1132.    If none of the built-in styles is appropriate, you'll probably want
  1133. to add a new style definition.  Styles are kept in the `c-style-alist'
  1134. variable, but you probably won't want to modify this variable directly.
  1135. `cc-mode' provides a function, called `c-add-style', that you can use
  1136. to easily add new styles or update existing styles.  This function
  1137. takes two arguments, a STYLENAME string, and an association list
  1138. DESCRIPTION of style customizations.  If STYLENAME is not already in
  1139. `c-style-alist', the new style is added, otherwise the style already
  1140. associated with STYLENAME is changed to the new DESCRIPTION.  This
  1141. function also takes an optional third argument, which if non-`nil',
  1142. automatically institutes the new style in the current buffer.
  1143.  
  1144.    The sample `.emacs' file provides a concrete example of how a new
  1145. style can be added and automatically set.  *Note Sample .emacs File::.
  1146.  
  1147.    *<TBD: give some examples of the built-in styles>*
  1148.  
  1149. 
  1150. File: cc-mode.info,  Node: File Styles,  Prev: Adding Styles,  Up: Styles
  1151.  
  1152. File Styles
  1153. -----------
  1154.  
  1155.    The Emacs manual describes how you can customize certain variables
  1156. on a per-file basis by including a "Local Variable" block at the end of
  1157. the file.  So far, you've only seen a functional interface to
  1158. `cc-mode', which is highly inconvenient for use in a Local Variable
  1159. block.  `cc-mode' provides two variables that make it easier for you to
  1160. customize your style on a per-file basis.
  1161.  
  1162.    The variable `c-file-style' can be set to a style name string as
  1163. described in *Note Built-in Styles::.  When the file is visited,
  1164. `cc-mode' will automatically set the file's style to this style using
  1165. `c-set-style'.
  1166.  
  1167.    Another variable, `c-file-offsets', takes an association list
  1168. similar to what is allowed in `c-offsets-alist'.  When the file is
  1169. visited, `cc-mode' will automatically institute these offets using
  1170. `c-set-offset'.
  1171.  
  1172.    Note that file style settings (i.e. `c-file-style') are applied
  1173. before file offset settings (i.e. `c-file-offsets').
  1174.  
  1175. 
  1176. File: cc-mode.info,  Node: Advanced Customizations,  Prev: Styles,  Up: Customizing Indentation
  1177.  
  1178. Advanced Customizations
  1179. =======================
  1180.  
  1181.    For most users, `cc-mode' will support their coding styles with very
  1182. little need for customizations.  Usually, one of the standard styles
  1183. defined in `c-style-alist' will do the trick.  At most, perhaps one of
  1184. the syntactic symbol offsets will need to be tweaked slightly, or maybe
  1185. `c-basic-offset' will need to be changed.  However, some styles require
  1186. a more advanced ability for customization, and one of the real
  1187. strengths of `cc-mode' is that the syntactic analysis model provides a
  1188. very flexible framework for customizing indentation. This allows you to
  1189. perform special indentation calculations for situations not handled by
  1190. the mode directly.
  1191.  
  1192. * Menu:
  1193.  
  1194. * Custom Indentation Functions::
  1195. * Custom Brace and Colon Hanging::
  1196. * Customizing Semi-colons and Commas::
  1197. * Other Special Indentations::
  1198.  
  1199.